package com.nkym.wypan.enums.socket;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@AllArgsConstructor
@Getter
public enum WSRespTypeEnum {
    USERINFO_MESSAGE(0, "用户信息消息"),
    MESSAGE(1, "正常消息"),
    ERROR_MESSAGE(9, "错误消息"),
    ;

    private final Integer type;
    private final String desc;

    private static Map<Integer, WSRespTypeEnum> cache;

    static {
        cache = Arrays.stream(WSRespTypeEnum.values()).collect(Collectors.toMap(WSRespTypeEnum::getType, Function.identity()));
    }

    public static WSRespTypeEnum of(Integer type) {
        return cache.get(type);
    }
}